<!--
    group: 发票管理
    name: 申请开票
    item: 开票第一步
-->
<template>
  <div class="main_content">
    <!--选择发票类型-->
    <div class="selectType">
      <a-form-model-item label="请选择发票类型">
        <a-radio-group v-model="form.taxType" @change="onInvoiceChange">
          <a-radio :value="1" v-if="invoiceColumns.isSpecial">增值税专用发票</a-radio>
          <a-radio :value="2" v-if="invoiceColumns.isUniversal">增值税普通发票</a-radio>
        </a-radio-group>
      </a-form-model-item>
    </div>
    <h1 class="nameTitle">&nbsp;{{ invoiceName }}</h1>
    <!--购买方类型-->
    <div class="selectType" v-if="form.taxType == 2">
      <a-form-model-item label="购买方类型" prop="buyerType">
        <a-radio-group v-model="form.buyerType" @change="onBuyerTypeChange">
          <a-radio :value="1">公司</a-radio>
          <a-radio :value="2">个人</a-radio>
        </a-radio-group>
      </a-form-model-item>
    </div>

    <!--发票模板-->
    <a-form-model :model="form"
                  ref="ruleForm"
                  :label-col="labelCol" :wrapper-col="wrapperCol"
                  :rules="rules"
    >
      <div class="specifications">
        <a-row class="flex enterprise">
          <a-col :span='12' class="flex">
            <div style="width: 60px;">
              <div class='fontColor tone rightLine disFlex'>
                <span class="son">购</span><br/>
                <span class="son">买</span><br/>
                <span class="son">方</span><br/>
                <span class="son">信</span><br/>
                <span class="son">息</span>
              </div>
            </div>
            <div class="pLeft pTop padding" style="flex: 1;">
              <div class='common'>
                <span class='commonItemOne tone'>名称:</span>
                <div class="w100">
                  <a-form-model-item prop="entName">
                    <div style="display: flex;align-items: center;">
                      <a-auto-complete
                        v-model="form.entName"
                        placeholder="请填写购买方公司名称"
                        option-label-prop="value"
                        :defaultActiveFirstOption="false"
                        :allowClear="true"
                        @select="onSelect"
                        @search="onSearch"
                      >
                        <template slot="default">
                          <a-input v-model="form.entName" :maxLength="100" />
                        </template>
                        <template slot="dataSource">
                          <a-select-option
                            v-for="(item,index) in entListSource"
                            :key="index"
                            :value="item.name"
                            :entCode="item.creditCode"
                          >
                            <a-row type="flex" justify="space-between" align="middle">
                              <a-col v-html="item.name"></a-col>
                            </a-row>
                          </a-select-option>
                        </template>
                      </a-auto-complete>
                      <a-button @click="handleReceiverChange" type="link">历史购买方</a-button>
                    </div>
                    <p v-if="entInfo.tipStatus" class="red">{{ entInfo.tips }}</p>
                  </a-form-model-item>
                </div>
              </div>
              <div class='common'>
                <span class='commonItemOne tone'>统一社会信用代码/纳税人识别号:</span>
                <div class="w100">
                  <a-form-model-item prop="entCreditCode">
                    <a-input type="input" v-model="form.entCreditCode" placeholder="购买方纳税人识别号" />
                  </a-form-model-item>
                </div>
              </div>
            </div>
          </a-col>
          <a-col :span='12' class="flex" style="flex: 1;">
            <div style="width: 60px;">
              <div class='fontColor tone rightLine disFlex' style="border-left: 3px solid #9D6854;">
                <span class="son">销</span><br/>
                <span class="son">售</span><br/>
                <span class="son">方</span><br/>
                <span class="son">信</span><br/>
                <span class="son">息</span>
              </div>
            </div>
            <div class="pLeft pTop" style="flex: 1">
              <div class='common'>
                <span class='commonItemOne tone'>名称:</span>
                <div class="w100">
                  <a-form-model-item>
                    <span>{{ form.taxTitle }}</span>
                  </a-form-model-item>
                </div>
              </div>
              <div class='common'>
                <span class='commonItemOne tone'>统一社会信用代码/纳税人识别号:</span>
                <div class="w100">
                  <a-form-model-item>
                    <span>{{ form.taxCreditCode }}</span>
                  </a-form-model-item>
                </div>
              </div>
            </div>
          </a-col>
        </a-row>
        <a-row class="topLine" type="flex" justify="space-between">
          <a-col :span='6' class="align rightLine tone padding">项目名称</a-col>
          <a-col :span='2' class="align rightLine tone padding">规格型号</a-col>
          <a-col :span='2' class="align rightLine tone padding">单位</a-col>
          <a-col :span='2' class="align rightLine tone padding">数量</a-col>
          <a-col :span='2' class="align rightLine tone padding">单价</a-col>
          <a-col :span='3' class="align rightLine tone padding">金额</a-col>
          <a-col :span='2' class="align rightLine tone padding">税率</a-col>
          <a-col :span='2' class="align rightLine tone padding">税额</a-col>
          <a-col :span='3' class="align tone padding">价税合计</a-col>
        </a-row>
        <!-- 发票内容 -->
        <InvoicingDropDown
          ref="child"
          :taxContents="form.taxContents"
          :vatRates="vatRates"
          :taxType="form.taxType"
          :setVal="setTotalPrice"
          @handleFather="handleFather"
        />
        <a-row type="flex" justify="space-between">
          <a-col :span='6' class="align rightLine tone">合&nbsp;&nbsp;&nbsp;&nbsp;计</a-col>
          <a-col :span='2' class="align rightLine tone"></a-col>
          <a-col :span='2' class="align rightLine tone"></a-col>
          <a-col :span='2' class="align rightLine tone"></a-col>
          <a-col :span='2' class="align rightLine tone"></a-col>
          <a-col :span='3' class="align rightLine tone"></a-col>
          <a-col :span='2' class="align rightLine tone"></a-col>
          <a-col :span='2' class="align rightLine tone"></a-col>
          <a-col :span='3' class="align tone"></a-col>
        </a-row>
        <a-row class="flex topLine">
          <a-col :span='6' style="flex: 1;">
            <div class='fontColor tone rightLine padding'>
              价税合计（大写）
            </div>
          </a-col>
          <a-col :span='18' class='pLeft padding'>
            <a-col :span='14'>
              {{transFormMoney(form.totalPrice)}}
            </a-col>
            <a-col :span='4'>
              <div class="flex">
                <span class='tone' style="white-space: nowrap;margin-right: 20px;">（小写）</span>
                <span>{{ form.totalPrice }}</span>
              </div>
            </a-col>
          </a-col>
        </a-row>
        <a-row class="flex topLine">
          <a-col :span='24' class="flex">
            <div style="width: 60px;">
              <div class='fontColor tone rightLine disFlex'>
                <span class="son">备</span><br/>
                <span class="son">注</span>
              </div>
            </div>
            <div class='pTop pLeft padding' style="flex: 1;">
              <div>
                <div class="remarksBox">
                  <div class='common'>
                    <span class='commonItem'>销售方地址、电话:</span>
                    <div class="flex w100">
                      <a-form-model-item>
                        {{ form.taxAddress }}
<!--                        <a-input type="input" v-model="form.taxAddress" placeholder="请输入销售方地址" />-->
                      </a-form-model-item>
                      <a-form-model-item>
                        {{ form.taxPhone }}
<!--                        <a-input type="input" v-model="form.taxPhone" placeholder="请输入销售方电话" />-->
                      </a-form-model-item>
                    </div>
                  </div>
                  <!--显示在备注栏-->
                  <a-checkbox v-model="form.taxAddrFlag" @change="onRemarksChange($event,1)">
                    <span :class="[isRedShow && !form.taxAddrFlag  ? 'red' : '']">显示在备注栏</span>
                  </a-checkbox>
                </div>
                <div class="remarksBox">
                  <div class='common'>
                    <span class='commonItem'>销售方开户行、账号:</span>
                    <div class="flex w100">
                      <a-form-model-item prop="taxBankName">
                        <a-input type="input" v-model="form.taxBankName" placeholder="请输入销售方开户行" />
                      </a-form-model-item>
                      <a-form-model-item prop="taxBankAccount">
                        <!--  输入框禁止输入空格
                            oninput="value = value.replace(/[, ]/g,'')"
                            onkeyup="value = value.replace(/[, ]/g,'')"
                        -->
                        <a-input type="input" v-model="form.taxBankAccount" placeholder="请输入销售方账号" />
                      </a-form-model-item>
                    </div>
                  </div>
                  <a-checkbox v-model="form.taxBankFlag" @change="onRemarksChange($event,2)">
                    <span :class="[isRedShow && !form.taxBankFlag  ? 'red' : '']">显示在备注栏</span>
                  </a-checkbox>
                </div>
                <div class="remarksBox">
                  <div class='common'>
                  <span class='commonItem'>购买方地址、电话:</span>
                  <div class="flex w100">
                    <a-form-model-item prop="entAddress">
                      <a-input type="input" v-model="form.entAddress" placeholder="购买方公司地址" />
                    </a-form-model-item>
                    <a-form-model-item prop="entPhone">
                      <a-input type="input" v-model="form.entPhone" placeholder="购买方公司电话" />
                    </a-form-model-item>
                  </div>
                </div>
                  <a-checkbox v-model="form.entAddrFlag" @change="onRemarksChange($event,3)">
                    <span :class="[isRedShow && !form.entAddrFlag  ? 'red' : '']">显示在备注栏</span>
                  </a-checkbox>
                </div>
                <div class="remarksBox">
                  <div class='common'>
                  <span class='commonItem'>购买方开户行、账号:</span>
                  <div class="flex w100">
                    <a-form-model-item prop="entBankName">
                      <a-input type="input" v-model="form.entBankName" placeholder="购买方公司开户行" />
                    </a-form-model-item>
                    <a-form-model-item prop="entBankAccount">
                      <!--  输入框禁止输入空格
                            oninput="value = value.replace(/[, ]/g,'')"
                            onkeyup="value = value.replace(/[, ]/g,'')"
                        -->
                      <a-input type="input" v-model="form.entBankAccount" placeholder="购买方公司银行账号" />
                    </a-form-model-item>
                  </div>
                </div>
                  <a-checkbox v-model="form.entBankFlag" @change="onRemarksChange($event,4)">
                    <span :class="[isRedShow && !form.entBankFlag  ? 'red' : '']">显示在备注栏</span>
                  </a-checkbox>
                </div>
              </div>
              <div>
                <div style="flex: 1;padding: 5px;margin-top: 5px;">
                  <a-textarea v-model="form.entRemark" placeholder="票面备注" :maxLength="200" style="height: 100%" :auto-size="{ minRows: 3, maxRows: 5 }" />
                </div>
                <a-row style="margin-top: 10px;">
                  <a-col :span="8">
                    <div class="remarksBox">
                      <div class='common'>
                        <span class='commonItem'>收款人:</span>
                        <a-form-model-item prop="collectionUser">
                          <a-input v-model="form.collectionUser" placeholder="收款人姓名" />
                        </a-form-model-item>
                      </div>
                      <a-checkbox v-model="form.collectionFlag" @change="onRemarksChange($event,5)">
                        <span :class="[isRedShow && !form.collectionFlag  ? 'red' : '']">显示在备注栏</span>
                      </a-checkbox>
                    </div>
                  </a-col>
                  <a-col :span="8">
                    <div class="remarksBox">
                      <div class='common'>
                        <span class='commonItem'>复核人:</span>
                        <a-form-model-item prop="reviewUser">
                          <a-input v-model="form.reviewUser" type="input" placeholder="复核人姓名" />
                        </a-form-model-item>
                      </div>
                      <a-checkbox v-model="form.reviewFlag" @change="onRemarksChange($event,6)">
                        <span :class="[isRedShow && !form.reviewFlag  ? 'red' : '']">显示在备注栏</span>
                      </a-checkbox>
                    </div>
                  </a-col>
                  <a-col :span="6"></a-col>
                </a-row>
              </div>
            </div>
          </a-col>
        </a-row>
      </div>

      <div style="margin-top: 10px;margin-left: 65px;">
        <div class='common'>
          <span class='commonItemOne tone'>开 票 人:</span>
          <a-form-model-item>
            <a-button v-if="!form.invoiceUser" @click="selectInvoicer" type="primary" size="small">选择开票员</a-button>
            <span class="mLeft">
              {{ form.invoiceUser }}
              <span v-if="form.invoiceMethod == 2" class="red">{{ form.invoiceUserTips }}</span>
            </span>
            <a-button v-if="form.invoiceUser" @click="replaceInvoicer" type="primary" class="mLeft" size="small">更换开票员</a-button>
          </a-form-model-item>
        </div>
      </div>

      <div class="main_footer">
        <a-button :disabled="invoicerErrorModal.interfaceExecution" @click="checkNextStep" type="primary" class="btnsLarge">下一步</a-button>
        <a v-if="form.bizStatus != 103 && varyType != 1" @click="saveDraft" href="#" style="margin-left: 10px;text-decoration: underline;" v-preventReClick>保存草稿</a>
      </div>

    </a-form-model>

    <!-------------------------------------------------------------  选择发票类型 弹层 ↓   ------------------------------------------------------------>
    <div class="typeBox" v-if="isShowType">
      <div class="typeSmallBox">
        <a-icon @click="handleTypeVal" type="close" style="cursor: pointer;float: right;" />
        <div style="padding: 40px;">
          <h3 style="font-weight: bold;font-size: 20px;">请选择您要开具的发票类型</h3>
          <div style="margin-top: 40px;">
            <a-radio-group v-model="form.taxType" @change="onInvoiceChange">
              <a-radio :value="1" v-if="invoiceColumns.isSpecial">增值税专用发票</a-radio>
              <a-radio :value="2" v-if="invoiceColumns.isUniversal">增值税普通发票</a-radio>
            </a-radio-group>
          </div>
        </div>
      </div>
    </div>
    <!-------------------------------------------------------------  请选择历史购买方弹层 ↓   ---------------------------------------------->
    <a-modal
      :width="800"
      :footer="null"
      v-model="isPurchaserShow"
    >
      <h3>选择历史购买方</h3>
      <a-table bordered
               :pagination="false"
               :columns="columns"
               :data-source="receiverList"
               :scroll="{x:800,y:400}"
      >
        <!--操作-->
        <span slot="action" slot-scope="text,record">
          <a @click="selectBuyer(record)">选择</a>
        </span>
      </a-table>
    </a-modal>
    <!-------------------------------------------------------------  企业信息未找到提示框 ↓   ---------------------------------------------->
    <a-modal
      :footer="null"
      v-model="isEntUndefined"
    >
      <div class="exceedLimit">
        <div style="display: flex;">
          <a-icon type="exclamation-circle" style="color: red;font-size: 35px;" />
          <div>
            <h4>您提交的企业信息未找到！</h4>
            <p style="padding-left: 30px;font-size:16px;line-height: 25px;">
              信息错误可能会导致开票失败！<br/>
              请确认您填写的企业信息是否正确？
            </p>
          </div>
        </div>
        <div class="desc_btn">
          <a-button @click="entInfoBack" type="default">返回修改</a-button>
          <a-button @click="entInfoSure" type="primary" class="mLeft">确定</a-button>
        </div>
      </div>
    </a-modal>
    <!-------------------------------------------------------------  备注栏有信息未勾选提示框 ↓   ---------------------------------------------->
    <a-modal
      :footer="null"
      v-model="isRemarksCheckShow"
    >
      <div class="exceedLimit">
        <h4>
          <a-icon type="exclamation-circle" style="color: red;font-size: 35px;" />
          有信息未勾选！
        </h4>
        <div>
          您未勾选
          <template v-for="item in remarksCheckList">
            <a v-if="!item.value">{{ item.name }}，</a>
          </template>
          这些信息将不会显示在票面上，您确定要这样做吗？
        </div>
        <div class="desc_btn">
          <a-button @click="remarksBack" type="default">返回修改</a-button>
          <a-button @click="remarksSure" type="primary" class="mLeft">确定</a-button>
        </div>
      </div>
    </a-modal>
    <!-------------------------------------------------------------  保存草稿成功提示 ↓   ---------------------------------------------->
    <ModalCurrency
      :config="undoConfig"
      @fatherMethod="fatherMethod"
    />
    <!-------------------------------------------------------------  各类预警弹层提示 ↓   ---------------------------------------------->
    <InvoiceCoverPrompt
      :config="promptConfig"
      @fatherPromptMethod="fatherPromptMethod"
      @fatherPreserveMethod="fatherPreserveMethod"
    />
    <!-------------------------------------------------------------  变更征收方式弹层提示 ↓   ---------------------------------------------->
    <ChangeCollectionMethod
      v-if="id" :entId="id"
      :config="collectionConfig"
      @fatherBackMethod="fatherBackMethod"
    />
    <!-------------------------------------------------------------  选择开票员 弹层 ↓   ---------------------------------------------->
    <a-modal
      :footer="null"
      v-model="invoicerModal.invoicerStatus"
      @cancel="cancel"
    >
      <!--选择开票方式-->
      <div v-if="!invoicerModal.selectInvoiceUser">
        <h3>选择开票方式</h3>
        <div @click="activeItem(item.id,item)" v-for="item in invoicerList" :key="item.id" :class="[item.disabled ? 'flexItemDisabled' : '']" class="flexItem">
          <div>
            <h3>{{ item.name }}</h3>
            <span v-if="item.tips" class="red">{{ item.tips }}</span>
          </div>
          <p>{{ item.desc }}</p>
        </div>
      </div>
      <!--选择开票员-->
      <div v-if="invoicerModal.selectInvoiceUser">
        <h3>选择开票员</h3>
        <a-select v-model="invoiceUserInfo.invoiceUserId" placeholder="请选择开票员" @change="handleChange" :showSearch="true" :allowClear="true" style="width: 100%;margin: 20px 0 10px 0;">
          <a-select-option v-for="item in invoicerNewList" :value="item.id" :info="item" :key="item.id">
            {{ item.name }}
          </a-select-option>
        </a-select>
        <span class="red">{{ invoiceUserInfo.selectInvoiceTips }}</span>

        <div style="text-align: center;margin-top: 10px;">
          <a-button @click="changeSure" type="primary" style="width: 120px;">确定</a-button>
        </div>
      </div>
    </a-modal>
    <!-------------------------------------------------------------  开票员账号校验失败 弹层 ↓   ---------------------------------------------->
    <a-modal
      :width="800"
      :footer="null"
      v-model="invoicerErrorModal.visible"
    >
      <!--开票员账号校验失败-->
      <h3>开票员账号校验失败</h3>
      <div class="invoicerErrorModal">
        <div class="itemError">
          <h3>更换开票员</h3>
          <a-select v-model="invoiceUserInfo.invoiceUserId" placeholder="请选择开票员" @change="handleChange" :showSearch="true" :allowClear="true" style="width: 100%;margin: 20px 0 10px 0;">
            <a-select-option v-for="item in invoicerNewList" :value="item.id" :info="item" :key="item.id">
              {{ item.name }}
              （{{{1:'企业经营者',3:'开票员'}[item.type] || ''}}）
            </a-select-option>
          </a-select>
          <div style="text-align: center;margin-top: 10px;">
            <a-button @click="invoicerFailedSubmit" type="primary">提交开票</a-button>
          </div>
        </div>
        <div class="itemError">
          <h3>更新密码</h3>
          <a-form-model ref="failDoForm" :model="failForm" :rules="rules" v-bind="layout">
            <a-form-model-item label="开票人">
              {{ form.invoiceUser }}
            </a-form-model-item>
            <a-form-model-item label="新密码" prop="pass">
              <a-input-password v-model="failForm.pass" placeholder="请输入新密码" allowClear />
            </a-form-model-item>
            <p v-if="failForm.tips" class="red mLeft">{{ failForm.tips }}</p>
            <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }" style="margin-top: 20px;">
              <a-button @click="checkUserPassword" type="primary">校验密码</a-button>
            </a-form-model-item>
          </a-form-model>
        </div>
      </div>
    </a-modal>
    <!-------------------------------------------------------------  首次/单次开票金额限制弹层提示 ↓   ---------------------------------------------->
    <AmountLimitPrompt :config="excessConfig" @fatherExcessMethod="fatherExcessMethod" />
  </div>
</template>

<script>
import Vue from 'vue'
import { mapState } from 'vuex';
import {
  getReceiveList, getSendList, getTaxConfig,
  saveTaxInvoiceTem, getEntMoneyInfo, getEntSvConf,
  checkLimit, checkTransitLimit, getEntSearchTyc,
  verifyCompanyCode, queryInvoiceManage,
  userPasswordVerification,userPasswordUpdate,
} from '@/api/invoiceAdminister'
import {
  conversionElement,percentConversion, conversionBranch,
  cloneObject,accSub, accAdd,limitDigits,
  copyLinkContent, toChies
} from '@/utils/util'
import * as Regular from '@/views/invoice/utils/invoiceInputVerification'
import InvoicingDropDown from '@/views/invoice/modules/invoicingDropDown'   //发票类目
import ModalCurrency from '@views/invoice/common/modalCurrency.vue'  //保存草稿成功提示
import InvoiceCoverPrompt from '@views/invoice/common/invoiceCoverPrompt.vue'  //超额免征超服务模式弹层提示
import ChangeCollectionMethod from '@views/invoice/common/changeCollectionMethod.vue'  //变更征收方式弹层
import AmountLimitPrompt from '@views/invoice/common/amountLimitPrompt.vue' //变更征收方式弹层
export default {
  name: "addInvoiceCover",
  inject: ['reload'],
  components:{
    InvoicingDropDown,
    ModalCurrency,
    InvoiceCoverPrompt,
    ChangeCollectionMethod,
    AmountLimitPrompt,
  },
  props: ['detailsData'],
  data(){
    return{
      detailsId: null,   //详情id
      id: null,
      labelCol: { span: 8 },
      wrapperCol: { span: 20 },
      //选择发票类型弹层↓
      isShowType: false,
      invoiceName: '电子发票（普通发票）',   //发票名字
      vatRates: [],  // 选择增值税率
      //控制发票信息及上传文件的显隐
      invoiceColumns:{
        isSpecial: true,    //控制专票是否为可开票种
        isUniversal: true,  //控制普票是否为可开票种
        isSeparate: true,  //控制专普票下的纸质电子  true为专  false为普
        isZzTicket: false,  //专票纸质是否置灰
        isZdTicket: false,  //专票电子是否置灰
        isPzTicket: false,  //普票纸质是否置灰
        isPdTicket: false,  //普票电子是否置灰
        isVatType: false,    //控制增值税率
      },
      form:{
        taxType: null,  //2 普票 1 专票
        buyerType: null, //购买方类型 1公司 2个人
        // taxMedium: null,   //1 纸质 2 电子
        // paperType: 0,  //纸质电子类型
        // useSignature: false,  //电子签章
        //开票内容
        taxContents: [
          {
            invoiceTypeCode: null,   //发票类目
            invoiceTypeName: null,
            ultraLimit: null,  //是否超出企业设置的经营范围  1 是  0否
            money: null,   //发票金额（不含税）
            taxMoney: null,   //发票金额（含税）
            vatIndex: null,   //增值税率
            unit: null,   //单位
            spec: null,   //规格型号
            num: null,   //数量
            unitPrice: null,   //单价
            nameGenre: null,  //其他类别
            name: null,
            value: null,
            isShow: true,
          }
        ],

        entName: '',   //购买方信息---企业名称
        entCreditCode: '', //购买方信息---税号
        entAddress: '', //购买方信息---公司地址
        entPhone: '',  //购买方信息---电话
        entBankName: '',  //购买方信息---开户行
        entBankAccount: '',  //购买方信息---账号

        taxAddress: '',  //销售方信息---公司地址
        taxBankName: '-',  //销售方信息---开户行
        taxPhone: '',  //销售方信息---电话
        taxBankAccount: '-',  //销售方信息---账号

        entRemark: '',  //票面备注

        collectionUser: '', //收款人
        reviewUser: '', //复核人

        invoiceUser: '', //开票人
        invoiceMethod: '', //开票方式 1-线下手动开 2-线上接口开（数电）3-线上接口开（税控）
        invoiceUserType: '', //开票人类型 1 法人开票 2 代办开票 3 渠道

        isEntNameLawful: false,  //购买方信息校验合法标识
        taxAddrFlag: false,  //销售方地址、电话-备注栏开关
        taxBankFlag: false,  //销售方开户行、账号-备注栏开关
        entAddrFlag: false,  //购买方地址、电话-备注栏开关
        entBankFlag: false,  //购买方开户行、账号-备注栏开关
        collectionFlag: false,  //收款人-备注栏开关
        reviewFlag: false,  //复核人-备注栏开关
      },
      rules:{
        taxType:[{ required: true, message: '请选择发票种类', trigger: 'change' }],
        buyerType:[{ required: false, message: '请选择购买方类型', trigger: 'change' }],
        // paperType:[{ required: false, message: '请选择发票类型', trigger: 'change' }],

        entName:[
          { required: true, message: '请输入企业名称', trigger: 'blur' },
          { validator: Regular.validateEnterprise }
        ],
        entCreditCode: [
          { required: false, message: '请输入税号', trigger: 'blur' },
          { validator: Regular.verifyPlainTax }
        ],
        taxBankName: [
          { required: true, message: '请输入销售方开户行', trigger: 'blur' },
          { validator: Regular.verifySellingBank }
        ],
        taxBankAccount: [
          { required: true, message: '请输入销售方账号', trigger: 'blur' },
          { validator: Regular.verifySellingAccount }
        ],
        entAddress: [{ required: false, message: '请输入购买方公司地址', trigger: 'blur' }],
        entPhone: [
          { required: false, message: '请输入购买方公司电话', trigger: 'blur' },
          { validator: Regular.validatePhone2 }
        ],
        entBankName: [
          { required: false, message: '请输入购买方公司开户行', trigger: 'blur' },
          { validator: Regular.verifyBuyBank }
        ],
        entBankAccount: [
          { required: false, message: '请输入购买方公司银行账号', trigger: 'blur' },
          { validator: Regular.verifyBuyAccount }
        ],
        collectionUser: [
          { required: false, message: '请输入收款人', trigger: 'blur' },
        ],
        reviewUser: [{ required: false, message: '请输入复核人', trigger: 'blur' }],
        invoiceUser: [{ required: false, message: '请输入开票人', trigger: 'blur' }],
        invoiceUserType: [{ required: true, message: '请选择开票人', trigger: 'change' }],
        pass: [
          { required: true, message: '请输入密码', trigger: 'change' },
          { validator: Regular.validatePass }
        ],
      },

      //请选择历史购买方弹层↓
      isPurchaserShow: false,
      receiverList: [],   //购买方列表
      columns: [
        {
          title: '购买方名称',
          dataIndex: 'entName',
          width: 120,
          align: 'center'
        },
        {
          title: '购买方税号',
          dataIndex: 'entCreditCode',
          ellipsis: true,
          width: 150,
          align: 'center'
        },
        {
          title: '购买方地址',
          dataIndex: 'entAddress',
          ellipsis: true,
          width: 180,
          align: 'center'
        },
        {
          title: '购买方电话',
          dataIndex: 'entPhone',
          ellipsis: true,
          width: 180,
          align: 'center'
        },
        {
          title: '购买方开户行',
          dataIndex: 'entBankName',
          width: 150,
          ellipsis: true,
          align: 'center'
        },
        {
          title: '购买方账号',
          dataIndex: 'entBankAccount',
          width: 150,
          ellipsis: true,
          align: 'center'
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: {customRender: 'action'},
          align: 'center',
          fixed: 'right',
          width: 80
        },
      ],

      //购买方校验
      entListSource: [],
      entInfo:{
        tips: null,  //购买方公司名称提示
        tipStatus: false,  //购买方公司名称校验
      },
      isEntUndefined: false,  //企业信息未找到提示弹层显隐

      newDetailsData:{},
      partyList: [],   //销售方列表
      emailData: [],  //邮箱信息

      //保存草稿成功
      undoConfig:{
        width: '500px',  //modal宽度
        visible: false,    //modal展示状态
        modalTitle: '',   //modal层的标题
        icon: 'check-circle',
        iconColor: '#52c41a',
        iconSize: '35',
        title: '保存成功！',     //标题
        subTitle: '',     //副标题
        content: '您可以在草稿箱查看或直接提交。',  //内容
        okText: '返回发票详情',    //确定文字
        okType: 'default',    //确定类型
        cancleText: '返回发票列表',    //取消文字
        cancleType: 'primary',    //取消类型

        source: 5,    //来源  ''发送成功  1撤销并删除 2邀请验证 3确认寄送 4删除草稿 5保存草稿
        cancleRoute: '/invoice/invoiceQueryNew',     //跳转路由
      },

      isRemarksCheckShow: false, //备注栏提示弹层显隐
      remarksCheckList: [
        {
          type: 1,
          name: '销售方地址、电话',
          index: 'taxAddrFlag',
          value: null
        },
        {
          type: 2,
          name: '销售方开户行、账号',
          index: 'taxBankFlag',
          value: null
        },
        {
          type: 3,
          name: '购买方地址、电话',
          index: 'entAddrFlag',
          value: null
        },
        {
          type: 4,
          name: '购买方开户行、账号',
          index: 'entBankFlag',
          value: null
        },
        {
          type: 5,
          name: '收款人',
          index: 'collectionFlag',
          value: null
        },
        {
          type: 6,
          name: '复核人',
          index: 'reviewFlag',
          value: null
        },
      ],  //未提交信息展示
      isRedShow: false,  //控制备注栏显隐

      //数电类型
      digitalInfo:{
        ticketType: null,  //开票类型 1-传统票 2-数电票 3-混合票
        approvalMethod: 2,   //核定方式 1-查账征收 2-核定征收-双定 3-核定征收-征收率 4-核定征收-应纳税所得率
      },

      //年季月开票金额与限制金额
      amountColumn: {
        yearTotalMoney: 0,  //年度剩余开票金额
        yearMoney: 0,  //年度开票金额
        quarterMoney: 0,  //当季开票金额
        quarterLimit: 0, //季度最大开票限额
        monthMoney: 0,  //当月开票金额
        monthLimit: 0, //当月最大开票限额(服务模式)
        digitalMonthLimit: 0, //数电月度最大限额
        limitOfHalf: 0, //数电限额1/2
        limitOneThird: 0, //数电限额1/3
        yearLimit: 470000000,  //企业年度封顶金额470万元
      },
      //弹层展示各类金额
      promptColumn:{
        digitalMonthLimit: 0,   //数电月限额
        totalYear: 0,  //年度累计开票金额（含本次）
        totalQuarter: 0,  //季度累计开票金额（含本次）
        totalMonth: 0,  //月度累计开票金额（含本次）
        monthLimit: 0,  //服务模式月限额
        quarterLimit: 0,  //季度最大开票限额
      },
      //超额提示
      promptConfig: {
        width: '650px',
        visible: false,    //modal展示状态
        modalTitle: '',   //modal层的标题
        title: '',     //标题
        content: '',  //内容
        okText: '继续提交',    //确定文字
        okType: 'primary',    //确定类型
        cancleText: '暂不提交',    //取消文字
        cancleType: 'default',    //取消类型
        expandText: '',    //拓展文字
        source: 1,    //来源  在途-1 无在途-2
        category: '',    //类别
      },

      //征收方式变更
      collectionConfig: {
        width: '800px',
        visible: false,
        source: '',
        base: 'apply',   //出发地   apply-申请开票   list-开票列表
        isOverrun: 1
      },

      //选择开票员
      invoiceUserInfo: {
        invoiceUser: null,    //开票人姓名
        invoiceUserId: null,    //开票员id
        invoiceUserType: null,    //开票人类型 1 法人开票 2 代办开票 3 渠道
        invoiceMethod: null,    //开票方式 1-线下手动开 2-线上接口开
        selectInvoiceTips: '您选择的开票员为企业法人',  //选择开票员文案提示
      },  //存储相关开票员信息
      invoicerModal: {
        invoicerStatus: false,
        selectInvoiceUser: false,
        invoiceInfo: {},  //开票员信息
      },
      invoicerList: [
        {
          id: 2,
          name: '接口开票',
          tips: '付款后秒开',
          desc: '企业法人或渠道指定开票员，需开票员在每日首次开票时，完成电子税务局核验',
          disabled: false,
        },
        {
          id: 1,
          name: '常规开票',
          desc: '付款后人工开票，开票人以实际为准',
          disabled: false,
        }
      ],
      invoicerNewList: [],  //开票员数据
      //开票员账号校验失败
      failForm: {},
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 },
      },
      invoicerErrorModal: {
        visible: false,
        interfaceExecution: false,   //控制下一步校验开票员密码接口未成功前不能点击按钮
      },
      varyType: null,  // 1-详情变更申请

      //首次/单次开票金额限制弹层
      excessConfig: {
        width: '650px',
        visible: false,    //modal展示状态
        modalTitle: '',   //modal层的标题
        title: '首次开票金额不能超过您核定额度的1/3！',     //标题
        content: '',  //内容
        okText: '',    //确定文字
        okType: '',    //确定类型
        cancleText: '',    //取消文字
        cancleType: '',    //取消类型
        source: 1,    //来源  1-申请开票（首次开票金额限制）  2-申请开票（单次开票金额限制）  3-提交结算（首次开票金额限制）
      }

    }
  },
  created() {
    this.id = this.$route.query.bizId;
    //从详情 变更申请 发起
    if (this.$route.query.varyType){
      this.varyType = this.$route.query.varyType;
    }
    this.getPartyList();   //获取销售方信息
  },
  mounted() {
    if(this.$route.query.detailsId || this.newDetailsData.taxType) {
      this.isShowType = false;
    } else {
      this.isShowType = true;
    }

    this.getMoneyInfo();   //获取开票金额
    this.getMonthLimit();   //获取当前企业月度最大限额

    this.getDraweeList();   //获取购买方信息

    this.getUserManageList();   //获取开票员信息
  },
  computed:{
    ...mapState({
      totalPrice: state => state.invoice.totalPrice,  //开票总金额
      amountNum: state => state.invoice.amountNum,  //开票数量
      vatReason: state => state.invoice.vatReason,  //优惠政策原因
      vatIndex: state => state.invoice.vatIndex,  //专票增值税id
      vatRate: state => state.invoice.vatRate,  //专票增值税税率
    }),
  },
  watch:{
    detailsData:{
      handler(vals) {
        let val = cloneObject(vals);
        if (val){
          // console.log(1,val)
          this.newDetailsData = val;
          //判断对象是否为空  JSON.stringify(val) === "{}"
          if (JSON.stringify(val) === "{}"){
            this.isShowType = true;
          }else{

            this.isShowType = val.isShowType;
            this.$nextTick(()=>{
              this.form.taxType = val.taxType;
            })

            this.isShowType = val.isShowType;
            this.form = val;

            //判断详情里是否有传统、数电票字段 ticketType
            if(val.hasOwnProperty('ticketType')){

            }else{
              this.form.ticketType = 1;
            }

            //判断开票员类型
            if(this.form.invoiceMethod == 1){
              this.form.invoiceUser = '代开（以实际开票人为准）';
            }

            //判断备选框值为true时，对应校验位必填项
            if (this.form.taxBankFlag){
              this.rules.taxBankName[0].required = true;
              this.rules.taxBankAccount[0].required = true;
            }
            if (this.form.entAddrFlag){
              this.rules.entAddress[0].required = true;
              this.rules.entPhone[0].required = true;
            }
            if (this.form.entBankFlag){
              this.rules.entBankName[0].required = true;
              this.rules.entBankAccount[0].required = true;
            }
            if (this.form.collectionFlag){
              this.rules.collectionUser[0].required = true;
            }
            if (this.form.reviewFlag){
              this.rules.reviewUser[0].required = true;
            }


            //判断普票,专票 普通 2  专用 1
            if (this.form.taxType == 2){
              this.invoiceName = '电子发票（普通发票）';
            }else{
              this.invoiceName = '电子发票（增值税专用发票）';
            }
          }
          this.initializationFun();
        }
      },
      deep:false,
      immediate:true
    },
    totalPrice:{
      handler(currVal) {
        // 监听mapState中的变量，当数据变化（有值、值改变等），
        // 保证能拿到完整的数据，不至于存在初始化没有数据的问题，然后可以赋给本组件data中的变量
        this.$nextTick(()=>{
          this.form.totalPrice = currVal;

          let data = cloneObject(currVal);
          let a = conversionBranch(data);
          let b = accAdd(a,this.amountColumn.quarterMoney); //获取当季度已开金额
          this.form.quarterTotalPrice = conversionElement(b);
          let c = accAdd(a,this.amountColumn.monthMoney); //获取月度已开金额
          this.form.totalMonthPrice = conversionElement(c);
        })
        this.$forceUpdate();
      },
      deep:false,
      immediate:true
    },
  },
  methods:{
    setTotalPrice(val){
      this.form.totalPrice = val;
    },
    setFormData(dbData){
      Object.keys(this.form).forEach(key=>{
        const tempVal = dbData[key]
        if(tempVal){
          this.form[key] = tempVal
        }
      })
    },
    //初始化执行
    initializationFun(){
      if(this.$route.query.detailsId || this.newDetailsData.taxType) {
        // if (this.newDetailsData.taxContents) {
        //   this.$nextTick(() => {
        //     let bool = this.newDetailsData.taxContents.every(item => {
        //       return item.ultraLimit == 0;
        //     });
        //   })
        //
        // }
      } else {
        this.isShowType = true;
      }
    },
    //  ---------------------------- 判断专普票购买方类型选择事件 ↓ -------------------------------
    //判断普票,专票
    onInvoiceChange(e) {
      if(e.target.value){
        //自动关闭弹层
        this.isShowType = false;
        //普通 2  专用 1
        if (e.target.value == 2){
          this.invoiceName = '电子发票（普通发票）';
          this.rules.entCreditCode[0].required = false;
        }else{
          this.invoiceName = '电子发票（增值税专用发票）';
          this.form.buyerType = null;
          this.rules.entCreditCode[0].required = true;
        }
        //将vuex税率重置
        this.$store.dispatch('deleteInvoiceVat');
        //将发票类型存储
        this.$store.dispatch('setInvoiceType', e.target.value);
      }

    },
    //选择发票类型关闭事件（弹层）
    handleTypeVal(e){
      if (this.form.taxType){
        this.isShowType = false;
        //将发票类型存储
        this.$store.dispatch('setInvoiceType', this.form.taxType);
      }else{
        this.$message.warning('请先选择发票类型');
        this.isShowType = true;
      }
    },
    //判断购买方类型
    onBuyerTypeChange(e) {
      if(e.target.value){
        //buyerType  1-公司 2-个人
        if (e.target.value == 1){
          this.rules.entCreditCode[0].required = true;
        }else{
          this.rules.entCreditCode[0].required = false;
        }
      }
    },
    //  ---------------------------- 判断选择开票员/更换开票员事件 ↓ -------------------------------
    //选择开票员
    selectInvoicer(){
      this.invoicerModal.invoicerStatus = true;
    },
    //切换开票员方式
    activeItem(index,item){
      this.invoiceUserInfo.invoiceMethod = index;
      if(this.invoiceUserInfo.invoiceMethod == 1){
        this.form.invoiceMethod = 1;  //开票方式 1-线下手动开 2-线上接口开
        this.form.invoiceUserType = 2;  //开票人类型 1 法人开票 2 代办开票 3 渠道
        this.form.invoiceUser = '代开（以实际开票人为准）';
        this.form.invoiceUserId = '';  //清空开票人id
        // delete this.form.invoiceUserId;   //删除开票人id字段

        this.invoicerModal.invoicerStatus = false;
      }else {
        this.invoicerModal.selectInvoiceUser = true;
      }
    },
    //请选择开票员
    handleChange(value,option){
      //获取其他信息  option.data.attrs.info
      if (value){
        let data = option.data.attrs.info;
        // console.log('开票员其他信息==>',data)
        this.invoiceUserInfo.invoiceUserId = value;
        this.invoicerModal.invoiceInfo = data;
        //type 1 法人开票(经营者) 2 代办开票 3 开票人-身份渠道
        data.type == 3 ? this.invoiceUserInfo.selectInvoiceTips = '您选择的开票员为渠道员工' : this.invoiceUserInfo.selectInvoiceTips = '您选择的开票员为企业法人';
      }
    },
    //确定
    changeSure(){
      if (this.invoicerModal.invoiceInfo && this.invoicerModal.invoiceInfo.name){
        this.form.invoiceUser = this.invoicerModal.invoiceInfo.name;
        this.form.invoiceUserId = this.invoicerModal.invoiceInfo.id;
        //type 1 法人开票(经营者) 2 代办开票 3 开票人-身份渠道
        this.form.invoiceUserType = this.invoicerModal.invoiceInfo.type;
        this.form.invoiceMethod = 2;  //开票方式 1-线下手动开 2-线上接口开
        this.form.invoiceUserTips = this.invoiceUserInfo.selectInvoiceTips;  //提示文案

        this.invoicerModal.invoicerStatus = false;
        this.invoicerModal.selectInvoiceUser = false; //选择开票方式
      }else {
        this.$message.warning('请选择开票员');
      }
    },
    //取消开票方式弹层
    cancel(){
      if (this.form.invoiceMethod == 2){
        this.invoiceUserInfo.invoiceUser = this.form.invoiceUser;
        this.invoiceUserInfo.invoiceUserId = this.form.invoiceUserId;
        this.invoiceUserInfo.invoiceUserType = this.form.invoiceUserType;
        this.invoiceUserInfo.selectInvoiceTips = this.form.invoiceUserTips;
      }

      this.invoicerModal.invoicerStatus = false;
      this.invoicerModal.selectInvoiceUser = false; //选择开票方式
    },
    //更换开票员
    replaceInvoicer(){
      this.invoicerModal.invoicerStatus = true;
    },
    //  ---------------------------- 开票员账号校验失败弹层事件 ↓ -------------------------------
    //提交开票
    invoicerFailedSubmit(){
      if (this.invoicerModal.invoiceInfo && this.invoicerModal.invoiceInfo.name){
        this.form.invoiceUser = this.invoicerModal.invoiceInfo.name;
        this.form.invoiceUserId = this.invoicerModal.invoiceInfo.id;
        //type 1 法人开票(经营者) 2 代办开票 3 开票人-身份渠道
        this.form.invoiceUserType = this.invoicerModal.invoiceInfo.type;
        this.form.invoiceMethod = 2;  //开票方式 1-线下手动开 2-线上接口开
        this.form.invoiceUserTips = this.invoiceUserInfo.selectInvoiceTips;  //提示文案

        //请求接口继续校验 成功关闭弹层  失败返回继续验证
        let params = {};
        params.entId = this.id;  //企业id
        params.parentId = this.form.invoiceUserId;  //开票人id

        //接口开票需要校验开票人
        this.checkUserTicketPassword(params,2);

      }else {
        this.$message.warning('请选择开票员');
      }
    },
    //校验密码
    checkUserPassword(){
      this.$refs.failDoForm.validate(valid => {
        if (valid) {
          let params = {};
          params.entId = this.id;  //企业id
          params.parentId = this.form.invoiceUserId;  //开票人id
          params.id = this.failForm.id;  //开票员与企业关联的唯一ID
          params.password = this.failForm.pass;  //密码

          //接口开票需要校验开票人
          this.checkUserTicketPassword(params,3);

        } else {
          return false;
        }
      });
    },
    //  ---------------------------- 保存草稿功能 ↓ -------------------------------
    //保存草稿
    saveDraft(){
      let data = this.getParamData();
      //处理开票内容
      if (data.taxContents.length > 0){
        for (let k=0; k<data.taxContents.length; k++) {
          //换算元转分
          data.taxContents[k].money = parseInt(conversionBranch(data.taxContents[k].money));
          data.taxContents[k].unitPrice = parseInt(conversionBranch(data.taxContents[k].unitPrice));

          if (!data.taxContents[k].invoiceTypeName && data.taxContents[k].name && data.taxContents[k].value){
            data.taxContents[k].invoiceTypeName = data.taxContents[k].name + '*' + data.taxContents[k].value;
          }
        }
      }
      //验证发票类目是否重复
      let repetition = this.$refs.child.categoriesRepetition();
      if (repetition){
        this.$message.warning('发票类目不能重复，请重新选择');
      }else{
        saveTaxInvoiceTem(data).then(res => {
          if (res.success) {
            this.detailsId = res.result;
            // this.entId = res.result;
            //将vuex税率重置
            this.$store.dispatch('deleteInvoiceVat');
            //保存草稿成功
            if (!this.promptConfig.isDraftShow){
              this.$nextTick(()=>{
                this.undoConfig.visible = true;
              })
            }
          }else{
            this.$message.warning(res.message);
          }
        })
      }
    },
    //保存草稿成功跳转路径
    fatherMethod(config) {
      //确定撤销
      this.$nextTick(() => {
        this.undoConfig.visible = false;
      })

      this.$router.push({
        path: '/invoice/applyInvoice',
        query:{
          bizId: this.id,
          detailsId: this.detailsId,
        }
      })

      //页面刷新
      this.reload();
    },
    //  ---------------------------- 提交前相关校验 ↓ -------------------------------
    //校验购买方类型是否为空
    buyerIsNull(){
      //taxType  1-专用 2-普通
      if(this.form.taxType == 2){
        //buyerType  1-公司 2-个人
        if (this.form.buyerType){
          return true;
        }else{
          this.$message.warning('请选择购买方类型!');
        }
      }else{
        return true;
      }
    },
    //校验信息备注是否填写
    remarkFun(){
      //再校验信息勾选是否为true
      let isRemarkVal = this.verifyRemarkValue();
      if(isRemarkVal){
        //校验首次/单次是否超限额
        // this.amountLimitFun();

        //判断各类超额弹层
        this.variousLayers();
      }else{
        this.isRemarksCheckShow = true;
      }
    },
    //校验首次是否超数电核定额度1/3
    amountLimitFun(){
      //TODO 首次开票金额不超过核定额度的1/3: 判断不存在历史发票 && 判断超过“发票限额（月）”的1/3
      let firstStatus = true;
      if (firstStatus){
        this.$nextTick(()=>{
          this.excessConfig = {
            visible: true,    //modal展示状态
            title: '首次开票金额不能超过您核定额度的1/3！',     //标题
            content: '您的核定额度为：月核定额度/月，首次开票金额不能超过月核定额度/3元，本次开票可能无法结算，请确认您的开票金额！',  //内容
            okText: '继续提交',    //确定文字
            okType: 'primary',    //确定类型
            cancleText: '修改金额',    //取消文字
            cancleType: 'default',    //取消类型
            source: 1,    //来源  1-申请开票（首次开票金额限制）  2-申请开票（单次开票金额限制）  3-提交结算（首次开票金额限制）
          }
        })
      }else{
        //校验单次是否超数电核定额度1/2
        this.singleExcessFun();
      }
    },
    //校验单次是否超数电核定额度1/2
    singleExcessFun(){
      //TODO 单次开票金额不超过核定额度的1/2: 判断开票金额是否超过其核定金额的1/2
      let singleStatus = true;
      if(singleStatus){
        this.$nextTick(()=>{
          this.excessConfig = {
            visible: true,    //modal展示状态
            title: '单次开票金额不能超过您核定额度的50%！',     //标题
            content: '您当前的核定额度为：月核定额度/月，单次开票金额不能超过月核定额度/2元，请修改您的开票金额！',  //内容
            cancleText: '确定',    //取消文字
            cancleType: 'primary',    //取消类型
            source: 2,    //来源  1-申请开票（首次开票金额限制）  2-申请开票（单次开票金额限制）  3-提交结算（首次开票金额限制）
          }
        })
      }else {
        //判断各类超额弹层
        this.variousLayers();
      }
    },
    //校验首次/单次是否超数电核定额度提示---primary按钮事件
    fatherExcessMethod(data){
      this.$nextTick(()=>{
        this.excessConfig.visible = false;
      })
      if (data.source == 1){
        //校验单次是否超数电核定额度1/2
        this.singleExcessFun();
      }
    },
    //校验企业名称是否存在
    checkEntName(){
      //this.form.entName  企业名称
      //taxType 1专票   buyerType 1公司
      if (this.form.taxType == 1 || (this.form.taxType == 2 && this.form.buyerType == 1)){
        let params = {};
        params.entName = this.form.entName;
        params.lisenceCreditCode = this.form.entCreditCode;
        verifyCompanyCode(params).then(res => {
          if (res.success) {
            this.entInfo.tipStatus = false;
            //购买方信息校验合法标识
            this.form.isEntNameLawful = true;
            this.remarkFun();  //校验信息备注是否填写
          }else{
            this.entInfo.tipStatus = true;
            //购买方信息校验合法标识
            this.form.isEntNameLawful = false;
            this.entInfo.tips = '未查到该企业信息或企业名称与统一社会信用代码不匹配,请确认填写是否正确！';
            this.isEntUndefined = true;
            // this.$message.warning(res.message);
          }
        })
      }else {
        this.remarkFun();  //校验信息备注是否填写
      }
    },
    //校验开票人是否为空
    issuedByIsMandatory(){
      //invoiceMethod 开票方式 //开票方式 1-线下手动开 2-线上接口开
      //invoiceUserType 开票人类型//开票人类型 1 法人开票 2 代办开票 3 渠道
      //invoiceUser 开票人
      //invoiceUserId 开票人ID
      let issuedByStatus;
      if(this.form.invoiceMethod){
        if (this.form.invoiceMethod == 2){
          if (this.form.invoiceUserType && this.form.invoiceUser && this.form.invoiceUserId){
            issuedByStatus = true;
          }else{
            issuedByStatus = false;
          }
        }else {
          if (this.form.invoiceUserType==2 && this.form.invoiceUser){
            issuedByStatus = true;
          }else{
            issuedByStatus = false;
          }
        }
      }else{
        issuedByStatus = false;
      }


      if (issuedByStatus){
        //校验开票人是否正确
        this.invoicerIsCorrect();
      }else{
        this.$message.warning('请先选择或更换开票员！');
      }
    },
    //校验开票人是否正确
    invoicerIsCorrect(){
      let params = {};
      params.entId = this.id;  //企业id
      params.parentId = this.form.invoiceUserId;  //开票人id
      //接口开票需要校验开票人
      if (this.form.invoiceMethod == 2){
        this.checkUserTicketPassword(params,1);
      }else {
        //校验购买方企业信息是否在第三方能查到
        this.checkEntName();
      }
    },
    //校验开票员是否登录正确
    checkUserTicketPassword(data,type){
      // type  1_下一步 2_提交开票 3_校验密码
      if(type == 3){
        userPasswordUpdate(data).then(res => {
          if (res.success) {
            this.invoicerErrorModal.visible = false;
            //校验购买方企业信息是否在第三方能查到
            this.checkEntName();
          }else{
            //判断异常码展示  30247-指定为密码失败
            let code = res.code;
            //超时提醒
            if(code == -2100230247){
              this.failForm.tips = '密码校验失败，请重新填写正确密码';
              this.$forceUpdate();
              this.invoicerErrorModal.visible = true;
            }else {
              this.$message.warning(res.message);
            }
          }
        })
      }else{
        this.invoicerErrorModal.interfaceExecution = true;
        userPasswordVerification(data).then(res => {
          if (res.success) {
            this.invoicerErrorModal.interfaceExecution = false;

            let data = res.result || {};
            this.failForm.id = data.id;
            if(data.verify){
              this.invoicerErrorModal.visible = false;
              //校验购买方企业信息是否在第三方能查到
              this.checkEntName();
            }else {
              //判断异常码展示  30247-指定为密码失败
              if (data.verifyCode == '30247'){
                if (type == 2){
                  this.$message.warning('校验失败！请更换开票员或重新校验密码');
                }
                this.invoicerErrorModal.visible = true;
              }else {
                this.$message.warning(data.message);
              }
            }
          }else{
            this.invoicerErrorModal.interfaceExecution = false;
            this.$message.warning(res.message);
          }
        })
      }
    },
    //  ---------------------------- 提交 ↓ -------------------------------
    //开票内容父组件接收子组件的值
    handleFather(child,totalPrice){
      this.form.taxContents = child;
      this.form.totalPrice = totalPrice;
    },
    //下一步
    checkNextStep(){
      //备注栏色值重置
      this.isRedShow = false;
      //校验购买方类型是否为空
      let buyerStatus = this.buyerIsNull();
      //验证开票内容必传 true 是 false 否
      let taxContentStatus = this.$refs.child.verificationContent();
      this.$refs.ruleForm.validate(valid => {
        if (taxContentStatus && buyerStatus && valid) {
          //开票类型 1-传统票 2-数电票 3-混合票
          if (this.digitalInfo.ticketType == 2){
            //校验开票人是否为空
            this.issuedByIsMandatory();
          }else{
            this.$message.warning('暂不支持开非数电发票！');
          }
        }else {
          return false;
        }
      })
    },
    //判断各类超额弹层
    variousLayers(){
      //增加超免征额判定
      let total = conversionBranch(this.form.totalPrice);  //本次开票金额

      //判断企业是否超过年度（超470万） 季度（核定征收方式） 月度（服务模式）额度 数电
      this.limitTotal(total);
    },
    //比对该企业总和是否超限额(无在途)
    limitTotal(num){
      //已开金额 + 预开金额  是否超过   剩余金额
      let totalMonth = accAdd(num,this.amountColumn.monthMoney);   //该月总用额度
      let totalQuarter = accAdd(num,this.amountColumn.quarterMoney);   //该季度总用额度
      let totalYear = accAdd(num,this.amountColumn.yearMoney);   //该年总用额度
      // console.log('月总用额度' + totalMonth)
      // console.log('月度限额' + this.amountColumn.monthLimit)
      // console.log('季度总用额度' + totalQuarter)
      // console.log('季度限额' + this.amountColumn.quarterLimit)
      // console.log('年总用额度' + totalYear)
      // console.log('年度限额' + this.amountColumn.yearLimit)
      this.promptColumn.totalYear = conversionElement(totalYear);  //年度累计开票金额（含本次）
      this.promptColumn.totalQuarter = conversionElement(totalQuarter);  //季度累计开票金额（含本次）
      this.promptColumn.totalMonth = conversionElement(totalMonth);  //月度累计开票金额（含本次）
      this.promptColumn.monthLimit = conversionElement(this.amountColumn.monthLimit);  //服务模式月限额
      this.promptColumn.quarterLimit = conversionElement(this.amountColumn.quarterLimit);  //季度最大开票限额
      this.promptColumn.digitalMonthLimit = conversionElement(this.amountColumn.digitalMonthLimit);  //数电月限额

      let totalNewQuarter;
      //判断核定方式
      this.digitalInfo.approvalMethod == 2  ? totalNewQuarter = totalMonth : totalNewQuarter = totalQuarter;

      checkLimit(this.id,num).then(res => {
        if (res.success) {
          //比对该企业总和是否超限额（有在途）
          this.limitTransitTotal(num);
        }else{
          //判断展示对应超额弹层
          let code = res.code;
          //开票金额超470万
          if(code == -210101311){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                modalTitle: '',   //modal层的标题
                title: '',     //标题
                okText: '修改开票金额',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '保存草稿',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '',    //拓展文字
                source: 2,
                category: 'cnd',    //类别
              };
              this.promptConfig.content = '您本次开票金额累计' + this.promptColumn.totalYear +'元（含本次），已超过470万/年，无法继续提交开票申请，请修改金额后重新提交！'
            })
          }
          //开票金额超征收限额
          else if (code == -210101312){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '修改开票金额',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '保存草稿',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '',    //拓展文字
                source: 2,
                category: 'czs',    //类别
              };
              this.promptConfig.content =
                '您本次开票金额累计' +
                this.promptColumn.totalQuarter +'元（含本次），已超过您适用的税收政策月限额：' +
                this.promptColumn.quarterLimit + '元，本月内不支持新开票！' + '<br/>' +
                '您可以修改开票金额后重新提交，或保存草稿，次月重新提交！'
            })
          }
          //开票金额超服务模式限额
          else if (code == -210101313){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '修改开票金额',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '保存草稿',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '',    //拓展文字
                category: 'cfwms',    //类别
                source: 2,
              };
              this.promptConfig.content =
                '您本次开票金额累计' +
                this.promptColumn.totalMonth +
                '元（含本次），已超过您适用的服务模式月限额：' +
                this.promptColumn.monthLimit +
                '元，本月内不支持新开票！' + '<br/>' +
                '您可以修改开票金额后重新提交，或保存草稿，次月重新提交'
            })
          }
          //开票金额超数电月限额
          else if (code == -210101314){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '继续提交',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '暂不提交',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '保存草稿',    //拓展文字
                category: 'sd',    //类别
                source: 2,    //来源  在途-1 无在途-2
              };
              this.promptConfig.content =
                '您累计提交的开票金额已超过月度核定开票额：' +
                this.promptColumn.digitalMonthLimit +
                '元，请联系客服，及时修改限额后再结算！'
            })
          }
          else {
            this.$message.warning(res.message);
          }
        }
      })

    },
    //比对该企业总和是否超限额（有在途）
    limitTransitTotal(num){
      //已开金额 + 预开金额  是否超过   剩余金额
      let totalMonth = accAdd(num,this.amountColumn.monthMoney);   //该月总用额度
      let totalQuarter = accAdd(num,this.amountColumn.quarterMoney);   //该季度总用额度
      let totalYear = accAdd(num,this.amountColumn.yearMoney);   //该年总用额度
      this.promptColumn.totalYear = conversionElement(totalYear);  //年度累计开票金额（含本次）
      this.promptColumn.totalQuarter = conversionElement(totalQuarter);  //季度累计开票金额（含本次）
      this.promptColumn.totalMonth = conversionElement(totalMonth);  //月度累计开票金额（含本次）
      this.promptColumn.monthLimit = conversionElement(this.amountColumn.monthLimit);  //服务模式月限额
      this.promptColumn.quarterLimit = conversionElement(this.amountColumn.quarterLimit);  //季度最大开票限额
      this.promptColumn.digitalMonthLimit = conversionElement(this.amountColumn.digitalMonthLimit);  //数电月限额

      let totalNewQuarter;
      //判断核定方式
      this.digitalInfo.approvalMethod == 2  ? totalNewQuarter = totalMonth : totalNewQuarter = totalQuarter;

      checkTransitLimit(this.id,num).then(res => {
        if (res.success) {
          //提交开票信息
          this.getInvoiceInfo();
        }else{
          //判断展示对应超额弹层
          let code = res.code;
          //开票金额超470万
          if(code == -210101311){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '继续提交',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '暂不提交',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '保存草稿',    //拓展文字
                source: 1,
                category: 'cnd',    //类别
              };
              this.promptConfig.content = '您累计提交的开票金额已超过470万/年，可能会有部分开票数据无法结算，请问您是否需要继续提交？'
            })
          }
          //开票金额超征收限额
          else if (code == -210101312){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '继续提交',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '暂不提交',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '保存草稿',    //拓展文字
                source: 1,
                category: 'czs',    //类别
              };
              this.promptConfig.content =
                '您累计提交的开票金额已超过您适用的税收政策月限额：' +
                this.promptColumn.quarterLimit +
                '元，可能会有部分开票数据无法结算，请问您是否需要继续提交？'
            })
          }
          //开票金额超服务模式限额
          else if (code == -210101313){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '继续提交',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '暂不提交',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '保存草稿',    //拓展文字
                category: 'cfwms',    //类别
                source: 1,
              };
              this.promptConfig.content =
                '您累计提交的开票金额已超过您适用的服务模式月限额：' +
                this.promptColumn.monthLimit +
                '元，可能会有部分开票数据无法结算，请问您是否需要继续提交？'
            })
          }
          //开票金额超数电月限额
          else if (code == -210101314){
            this.$nextTick(()=>{
              this.promptConfig = {
                width: '650px',
                visible: true,    //modal展示状态
                okText: '继续提交',    //确定文字
                okType: 'primary',    //确定类型
                cancleText: '暂不提交',    //取消文字
                cancleType: 'default',    //取消类型
                expandText: '保存草稿',    //拓展文字
                category: 'sd',    //类别
                source: 1,    //来源  在途-1 无在途-2
              };
              this.promptConfig.content =
                '您累计提交的开票金额已超过月度核定开票额：' +
                this.promptColumn.digitalMonthLimit +
                '元，可能会有部分开票数据无法结算，请问您是否需要继续提交？'
            })
          }
          else {
            this.$message.warning(res.message);
          }
        }
      })

    },
    //提交开票信息
    getInvoiceInfo(){
      let data = this.getParamData();
      this.$emit('handleStepFather',data,this.digitalInfo);
    },
    //处理提交参数
    getParamData(){
      let data = cloneObject(this.form);
      data.entId = this.id;
      if (this.$route.query.detailsId){

      }else{
        data.ticketType = this.digitalInfo.ticketType; //开票类型 1-传统票 2-数电票 3-混合票
      }
      //判断增值税率与文件格式上传
      if (data.taxType == 2){
        Vue.delete(data,'vatIndex');   //普票不传增值税字段
      }else{
        data.vatReason = this.vatReason;   //税率优惠政策原因
        data.vatIndex = this.vatIndex;   //专票增值税id
        data.vatRateTem = this.vatRate;   //专票增值税税率
      }
      data.isShowType = false;
      return data;
    },
    //  ---------------------------- 超额提示弹层返回判断 ↓ -------------------------------
    //各类预警弹层提示---primary按钮事件
    fatherPromptMethod(data){
      // console.log('接收到了子组件带来的参数',data)
      this.$nextTick(()=>{
        this.promptConfig.visible = false;
      })
      //在途票返回的确认方法
      if (data.source == 1){
        //提交开票信息
        this.getInvoiceInfo();
      }else{
        if (data.category == 'sd'){
          //提交开票信息
          this.getInvoiceInfo();
        }else {
          //弹层关闭   修改开票金额
        }
      }
    },
    //预警弹层提示---拓展按钮事件
    fatherPreserveMethod(data){
      this.$nextTick(()=>{
        this.promptConfig.visible = false;
      })
      //点击此处
      if (data.isDraftShow){
        this.promptConfig.isDraftShow = true;
        //展示变更征收方式弹层
        this.collectionConfig.visible = true;
      }
      //保存草稿
      this.saveDraft();
    },
    //解决超征收弹层与变更征收方式弹层反复变动
    collectionBackMethod(){
      //关闭变更征收方式弹层
      this.collectionConfig.visible = false;
    },
    //  ---------------------------- 征收方式变更返回回调 ↓ -------------------------------
    //返回上一步
    fatherBackMethod(){
      // console.log('我调到征收方式的子组件了！');
      //关闭变更征收方式弹层
      this.collectionConfig.visible = false;
      //展开超征收限额弹层 （无在途票，开票金额超征收限额）
      this.$nextTick(()=>{
        this.promptConfig.visible = true;
      })
    },
    //  ---------------------------- 企业信息未找到弹层相关 ↓ -------------------------------
    //企业信息未找到--确定
    entInfoSure(){
      this.isEntUndefined = false;
      //再校验信息勾选是否为true
      this.remarkFun();
    },
    //企业信息未找到--返回修改
    entInfoBack(){
      this.isEntUndefined = false;
    },
    //  ---------------------------- 备注栏勾选弹层相关 ↓ -------------------------------
    //备注栏--确定
    remarksSure(){
      this.isRemarksCheckShow = false;
      //判断各类超额弹层
      this.variousLayers();
    },
    //备注栏--返回修改
    remarksBack(){
      this.isRemarksCheckShow = false;
      //对应的选项给红色提示
      this.isRedShow = true;
    },
    //校验信息勾选是否为true
    verifyRemarkValue(){
      let formArr = Object.keys(this.form);
      for(let i=0;i<formArr.length;i++){
        this.remarksCheckList.forEach((itemVal, indexVal) => {
          if (itemVal.index == formArr[i]){
            this.remarksCheckList[indexVal].value = this.form[formArr[i]]
          }
        })
      }

      return this.remarksCheckList.every(item => {
        return item.value == true
      });
    },
    //根据备注栏勾选判断必填项是否校验
    onRemarksChange(e,type){
      //type 1-销售方地址、电话 2-销售方开户行、账号
      //type 3-购买方地址、电话 4-购买方开户行、账号
      //type 5-收款人 6-复核人
      let checked = e.target.checked;
      if (type == 1){
      }else if (type == 2){
        if (checked){
          this.rules.taxBankName[0].required = true;
          this.rules.taxBankAccount[0].required = true;
        }else{
          this.rules.taxBankName[0].required = false;
          this.rules.taxBankAccount[0].required = false;
        }
      }else if (type == 3){
        if (checked){
          this.rules.entAddress[0].required = true;
          this.rules.entPhone[0].required = true;
        }else{
          this.rules.entAddress[0].required = false;
          this.rules.entPhone[0].required = false;
        }
      }else if (type == 4){
        if (checked){
          this.rules.entBankName[0].required = true;
          this.rules.entBankAccount[0].required = true;
        }else{
          this.rules.entBankName[0].required = false;
          this.rules.entBankAccount[0].required = false;
        }
      }else if (type == 5){
        if (checked){
          this.rules.collectionUser[0].required = true;
        }else{
          this.rules.collectionUser[0].required = false;
        }
      }else if (type == 6){
        if (checked){
          this.rules.reviewUser[0].required = true;
        }else{
          this.rules.reviewUser[0].required = false;
        }
      }

    },
    //  ---------------------------- 获取获取开票金额和当季提醒限额 ↓ --------------------
    //获取开票金额
    getMoneyInfo(){
      let entId = this.id;
      getEntMoneyInfo(entId).then(res => {
        if (res.success) {
          let data = res.result;
          if (data){
            let dataNew = cloneObject(data);
            this.amountColumn.quarterMoney = dataNew.quarterMoney;  //当季开票金额
            this.amountColumn.yearTotalMoney = conversionElement(dataNew.yearBalanceMoney); //年度剩余开票金额
            this.amountColumn.yearMoney = dataNew.yearMoney;  //年度开票金额
            this.amountColumn.quarterLimit = dataNew.quarterMoneyLimit;  //季度最大开票限额
            this.amountColumn.monthMoney = dataNew.monthMoney;  //当月开票金额
          }
        }else{
          this.$message.warning(res.message);
        }
      })
    },
    //获取当前企业服务模式下的月度最大限额
    getMonthLimit(){
      let entId = this.id;
      getEntSvConf(entId).then(res => {
        if (res.success) {
          if (res.result){
            let data = res.result.invoiceMax || 0;
            this.amountColumn.monthLimit = data;
          }
        }else{
          this.$message.warning(res.message);
        }
      })
    },
    //  ---------------------------- 获取税率配置 ↓ --------------------
    //获取匹配的税率要求
    getTaxRequirements(){
      let params = {};
      params.entId = this.id;
      getTaxConfig(params).then(res => {
        if (res.success) {
          if (res.result){
            let data = cloneObject(res.result);
            this.digitalInfo.approvalMethod = res.result.approvalMethod;  //核定方式 1-查账征收 2-核定征收-双定 3-核定征收-征收率 4-核定征收-应纳税所得率

            //判断核定方式==2时，不支持开专票
            if (this.digitalInfo.approvalMethod == 2){
              this.invoiceColumns.isSpecial = false;
              //判断是传统票还是数电票  1-传统票 2-数电票 3-混合票
              if (this.digitalInfo.ticketType == 1){
                //判断该企业是否有开普票(isUniversal)的资格 true 可开,  false 不可开
                data[2] ? this.invoiceColumns.isUniversal = true : this.invoiceColumns.isUniversal = false;  //普票
              }else{
                this.invoiceColumns.isUniversal = true;
              }
            }else{
              //判断是传统票还是数电票  1-传统票 2-数电票 3-混合票
              if (this.digitalInfo.ticketType == 1){
                //判断该企业是否有开专普票的资格  true 可开,  false 不可开
                data[1] ? this.invoiceColumns.isSeparate = true : this.invoiceColumns.isSpecial = false;  //专票
                data[2] ? this.invoiceColumns.isUniversal = true : this.invoiceColumns.isUniversal = false;  //普票
              }else{
                this.invoiceColumns.isSpecial = true;
              }
            }


            //处理增值税率
            if (data && res.result.vatRate_1){
              if(res.result.vatRate_1.length > 0){
                let vatRates = res.result.vatRate_1;
                for (let k in vatRates) {
                  vatRates[k].value = percentConversion(vatRates[k].value);
                }
                this.vatRates = vatRates.filter(item => item.use);  //过滤use为true的值
              }
            }

          }
        }else{
          this.$message.warning(res.message);
        }
      })
    },
    //获取对应id的value值  增值税
    obtainCorrespondingValue(id,list){
      let hh = list.filter(function (item, index, list) {//第一个参数为当前项,第二个参数为索引,第三个为原值
        if (item.vatIndex == id) {
          return item
        }
      })

      //获取当前value的值
      if (hh && hh.length > 0){
        return hh[0].value;
      }
    },
    //  ---------------------------- 选择历史购买方 ↓ -------------------------------
    //购买方校验
    //搜索补全项的时候调用
    onSearch(vText) {
      this.entInfo.tipStatus = false;
      if(vText && vText.length >= 2){
        this.searchEntName(vText);
      }else{
        this.entListSource = [];
      }
    },
    //被选中时调用
    onSelect(value,option) {
      this.entInfo.tipStatus = false;
      let newValue = this.removeTagAndStyle(value);
      this.form.entName = newValue;
      if (newValue){
        if (option.data.attrs.entCode){
          this.form.entCreditCode = option.data.attrs.entCode;
        }else{
          this.form.entCreditCode = null;
        }
      }
    },
    //搜索查询企业名称
    searchEntName(value){
      const params = {
        word: value,   //关键字
        pageSize: 20,   //页面容量
        pageNum: 1,  //当前页
      };
      //taxType 1专票   buyerType 1公司
      if (this.form.taxType == 1 || (this.form.taxType == 2 && this.form.buyerType == 1)){
        if(value && value.length >= 2) {
          getEntSearchTyc(params).then(res => {
            let list = res.result.items || [];

            //接口拿到数据后，循环根据表单搜索的内容去做一个替换
            list.forEach(item => {
              this.$set(
                item,
                'name',
                item.name.replace(value, `<span style="color:red;">${value}</span>`)
              );
            });

            this.entListSource = list;
          });
        }else {
          this.entListSource = [];
        }
      }

    },
    //选择历史购买方
    handleReceiverChange(){
      this.isPurchaserShow = true;
    },
    //选择数据
    selectBuyer(list){
      this.isPurchaserShow = false;
      this.form.entName = list.entName;  //企业名称
      this.form.entCreditCode = list.entCreditCode;  //税号
      this.form.entAddress = list.entAddress;  //公司地址
      this.form.entPhone = list.entPhone;  //电话
      this.form.entBankName = list.entBankName;  //开户行
      this.form.entBankAccount = list.entBankAccount;  //账号
    },
    //获取购买方数据
    getDraweeList(){
      let entId = this.id;
      getReceiveList(entId).then(res => {
        if (res.success) {
          if (res.result){
            this.receiverList = res.result;

            //初始获取收款人复核人
            if (this.receiverList.length > 0){
              this.form.collectionUser = this.receiverList[0].collectionUser;  //收款人
              this.form.reviewUser = this.receiverList[0].reviewUser;  //复核人
            }
          }
        }else{
          this.$message.warning(res.message);
        }
      })
    },
    //  ---------------------------- 获取销售方信息/开票员列表 ↓ -------------------------------
    //获取销售方信息
    getPartyList(){
      let entId = this.id;
      getSendList(entId).then(res => {
        if (res.success) {
          if (res.result){
            this.partyList = res.result;

            //判断详情回显不展示默认值
            if (this.$route.query.detailsId){
              //获取数电相关数据
              if (res.result[0].entDetail){
                let juridicalDate = res.result[0].entDetail;
                this.digitalInfo.ticketType = juridicalDate.ticketType;  //开票类型 1-传统票 2-数电票 3-混合票
                this.amountColumn.digitalMonthLimit = juridicalDate.maxSdAmount;  //数电月度最大限额
                // this.amountColumn.limitOfHalf = juridicalDate.maxSdAmount21;  //数电限额1/2
                // this.amountColumn.limitOneThird = juridicalDate.maxSdAmount31;  //数电限额1/3
              }
            }else{
              if (res.result.length > 0){
                let registDetail = res.result[0].entDetail;
                let registrationTime = registDetail.lisenceRegisterTime;
                //向父组件传值 - 企业注册时间 ↓
                this.$emit('getRegistrationTime',registrationTime);

                this.form.taxBankName = res.result[0].taxBankName || '-';  //销售方开户行
                this.form.taxBankAccount = res.result[0].taxBankAccount || '-';  //销售方账号

                if (res.result[0].entDetail){
                  let juridicalDate = res.result[0].entDetail;
                  this.form.taxTitle = juridicalDate.entName;  //名称
                  this.form.taxCreditCode = juridicalDate.lisenceCreditCode;  //税号
                  this.form.taxAddress = juridicalDate.lisenceAddress;  //地址
                  this.form.taxPhone = juridicalDate.legalPhone;  //电话

                  // this.form.collectionUser = juridicalDate.legalName;  //收款人
                  // this.form.reviewUser = juridicalDate.legalName;  //复核人
                  // this.form.invoiceUser = juridicalDate.legalName;  //开票人

                  this.digitalInfo.ticketType = juridicalDate.ticketType;  //开票类型 1-传统票 2-数电票 3-混合票
                  this.amountColumn.digitalMonthLimit = juridicalDate.maxSdAmount;  //数电月度最大限额
                  // this.amountColumn.limitOfHalf = juridicalDate.maxSdAmount21;  //数电限额1/2
                  // this.amountColumn.limitOneThird = juridicalDate.maxSdAmount31;  //数电限额1/3
                }
              }
            }

            this.getTaxRequirements();   //获取匹配的税率要求

          }
        }else{
          this.$message.warning(res.message);
        }
      })
    },
    //获取开票员信息
    getUserManageList(){
      let entId = this.id;
      queryInvoiceManage(entId).then(res => {
        if (res.success) {
          let data = res.result ||[];
          // type 1 法人开票(经营者) 2 代办开票(内部员工) 3 开票人-身份渠道
          //判断列表是否包含内部员工
          let arr1 = data.filter(item => item.type == 2);
          if (arr1.length > 0){
            this.invoicerList[1].disabled = false;
          }else{
            this.invoicerList[1].disabled = true;
          }

          //处理过滤非内部员工数据
          this.invoicerNewList = data.filter(item => item.type != 2);

          //处理获取企业经营者
          let arr2 = data.filter(item => item.type == 1);
          if (arr2.length > 0){
            this.invoicerModal.invoiceInfo = arr2[0];
            this.invoiceUserInfo.invoiceUserId = arr2[0].id;
          }

        }else{
          this.$message.warning(res.message);
        }
      })
    },
    //  ---------------------------- 校验规则 ↓ -------------------------------
    //分转元
    scalerPrice(money){
      return conversionElement(money);
    },
    //金额小写转大写
    transFormMoney(val){
      // let num = conversionBranch(val);
      let num = val;
      return toChies(num)
    },
    //去除所有空格
    removeSpaces(value){
      var judgeFn = new RegExp(/\s+/g);
      if (judgeFn.test(value)) {
        return value.replace(/\s*/g,"");
      }else {
        return value;
      }
    },
    // 正则表达式匹配<span>标签以及其中的样式
    removeTagAndStyle(str) {
      return str.replace(/<span[^>]*>|<\/span>/g, '').replace(/style="[^"]*"/g, '');
    },
  }
}
</script>

<style scoped lang="less">
//公共
.tone{color: #9D6854;}
.mTop{margin-top: 10px;}
.padding{padding: 10px 0;}
.pTop{padding-top: 10px;}
.pLeft{padding-left: 20px;}
.topLine{border-top: 3px solid #9D6854;}
.rightLine{border-right: 3px solid #9D6854;}
.textLine{text-decoration: underline;cursor: pointer;}
.flex{display: flex;}
.align{text-align: center;}
.w100{width: 100%;}

//标题
h1{
  font-size: 30px;
  text-align: center;
  letter-spacing: 5px;
  margin-bottom: -10px;
}

//发票模板
.specifications{
  margin-top: 10px;
  width: 100%;
  border: 3px solid #9D6854;
}
.fontColor{
  width: 100%;
  height: 100%;
  font-size: 16px;
  text-align: center;
}

.disFlex{
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  //padding: 30px 0;
  padding: 5px 0;
}
.son{
  width: 100%;
}

.remarksBox{
  width: 90%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.common{
  flex: 1;
  display: flex;
  align-items: center;
}
.commonItem{
  white-space: nowrap;
  margin-right: 10px;
  width: 140px;
  display: inline-block;
  //text-align: right;
  text-align: left;
  font-size: 14px;
}

.ant-form-item{
  margin-bottom: 0;
  display: flex;
  width: 100%;
  justify-content: left;
}



//选择发票类型
.main_content{
  position: relative;
}
.typeBox{
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  position: absolute;
  top: 0;
  left: 0;
  z-index: 99;
  display: flex;
  justify-content: center;
  padding-top: 100px;
  .typeSmallBox{
    width: 400px;
    height: 200px;
    padding: 5px;
    background: #FFFFFF;
  }
}

//金额超限
.exceedLimit{
  width: 100%;
  padding: 20px 10px;
  color: #101010;
  h4{
    display: flex;
    align-items: center;
    font-weight: bolder;
    font-size: 20px;
    padding-left: 30px;
    margin-bottom: 20px;
    i{
      color: @color-orange;
      font-size: 50px;
      margin-right: 10px;
    }
  }
  .describe{
    margin-bottom: 20px;
    padding-left: 40px;
    font-size: 18px;
    line-height: 30px;
  }

  .describe1{
    padding-left: 40px;
    font-size: 19px;
    line-height: 40px;
    i{
      color: @color-orange;
      font-size: 40px;
      margin-right: 10px;
      line-height: 40px;
    }
  }
}
.desc_btn{
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  margin: 40px 0 20px 0;
  text-align: center;
}

//发票名字样式
.nameTitle{
  margin-bottom: 40px;
  color: #9D6854;
  text-decoration: underline double; //设置下划线  double双线
  text-underline-offset: 15px;  //下划线和文字间距
  text-decoration-color: #9D6854; //下划线颜色
  text-decoration-thickness: 2px; //修改下划线的大小为2像素
}

//第一层面的企业信息
.enterprise{
  .disFlex{
    font-size: 14px;
  }
  .common:nth-child(1){
    margin-bottom: 20px;
  }
}
//名称、统一社会信用代码输入框
.commonItemOne{
  white-space: nowrap;
  margin-right: 10px;
  display: inline-block;
  font-size: 14px;
}

//选择开票方式弹层样式
.flexItem{
  display: flex;
  align-items: center;
  border: 1px solid #cccccc;
  border-radius: 10px;
  margin-top: 30px;
  cursor: pointer;
  div:nth-child(1){
    width: 120px;
    min-height: 80px;
    text-align: center;
    border-right: 1px solid #cccccc;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    h3{
      font-weight: bolder;
      white-space: nowrap;
    }
  }
  p:nth-child(2){
    padding-left: 20px;
    width: 100%;
    margin-bottom: 0;
  }
}
.activeFlexItem{
  background: rgba(86,119,237,0.1);
}
.flexItem:hover{
  background: rgba(86,119,237,0.1);
}
.flexItemDisabled{
  pointer-events: none;
  background: rgba(43,43,43,0.14);
  border: none;
}


//开票员账号校验失败弹层
.invoicerErrorModal{
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin: 20px 0;
  .itemError{
    width: 45%;
    min-height: 200px;
    border: 1px solid #cccccc;
    border-radius: 10px;
    padding: 20px;
  }
}
</style>
